﻿
$(document).ready(function() {
    $("#tabs").tabs();

    $("#Form1").validate({
        rules: { ddlCategoryId: "required", txtTitle: "required" },
        messages: { ddlCategoryId: " 必填项", txtTitle: " 必填项" }
    });

    $("#UP_PicUrl").uploadify({
        height: 30,
        'multi': false,
        swf: "/Scripts/Uploadify/uploadify.swf",
        uploader: "/Scripts/Uploadify/UploadHandler.ashx",
        width: 120,
        cancelImg: "/Scripts/Uploadify/uploadify-cancel.png",
        buttonText: "上传图片",
        fileTypeExts: "*.gif;*.jpg;*.jpeg;*.png",
        fileSizeLimit: "6000KB",
        removeCompleted: true,
        formData: {
            PicW: $("#txtPicW").val(),
            PicH: $("#txtPicH").val(),
            BiLi: $("#cbkBiLi").prop("checked")
        },
        onUploadSuccess: function(file, data, response) {
            //上传完成时触发（每个文件触发一次）
            if (data.indexOf("错误提示") > -1) {
                alert(data);
            } else {
                $("#txtPicUrl").val(data);
            }
        },
        onUploadError: function(file, errorCode, errorMsg, errorString) {
            //当单个文件上传出错时触发
            alert("文件：" + file.name + " 上传失败: " + errorString);
        }
    });

    $("#UP_PhotoList").uploadify({
        height: 30,
        'multi': true,
        swf: "/Scripts/Uploadify/uploadify.swf",
        uploader: "../DataHandler.ashx?Action=UpdatePhotoList",
        width: 120,
        cancelImg: "/Scripts/Uploadify/uploadify-cancel.png",
        buttonText: "上传图片",
        fileTypeExts: "*.gif;*.jpg;*.png;*.swf",
        fileSizeLimit: "6000KB",
        removeCompleted: true,
        'debug': false,
        formData: {
            ContentId: Request.QueryString("ID") == null ? -1 : Request.QueryString("ID"),
            ModelId: Request.QueryString("ModelId"),
            TempFlag: Request.QueryString("TempFlag") == null ? "" : Request.QueryString("TempFlag")
        },
        onUploadSuccess: function(file, data, response) {
            if (data.indexOf("错误提示") > -1) {
                alert(data);
            } else {
                var info = $.parseJSON(data);
                PhotoListItem(info);
            }
        },
        onUploadError: function(file, errorCode, errorMsg, errorString) {
            alert("文件：" + file.name + " 上传失败: " + errorString);
        }
    });

    loadPhotoList();


    $("#thumbnails").sortable({
        start: function(event, ui) {
            ui.item.addClass("active");
        },
        stop: function(event, ui) {
            ui.item.removeClass("active").effect(
                "highlight",
                { color: "#000" }, 1000, function() {
                    $.each($(".thumbshow"), function(index, event) {
                        $(this).children("span").html(index + 1);
                    });
                });
            moveOrderIdPhotoList();
        }

    });
    $("#thumbnails").disableSelection();
});

function ColorPalette() {
    var str = window.showModalDialog("../Images/JS拾色器/JS拾色器.htm", "dialogWidth=190px;dialogHeight=80px");
    if (typeof (str) != "undefined") {
        $get("txtColorStyle").value = str;
        LoadStyle();
    }
}

function LoadStyle() {
    if ($get("txtColorStyle") == null) {
        return;
    }
    if ($get("imgColorStyle") == null) {
        return;
    }
    var str = $get("txtColorStyle").value;
    if (str == "") {
        $get("imgColorStyle").style.backgroundColor = "#000000";
    } else {
        $get("imgColorStyle").style.backgroundColor = str;
    }
}

function GetImage() {
    $("#dialog-modal").dialog({
        height: 540,
        width: 540,
        title: "图片浏览",
        modal: true
    });
    var urlC = $("#dialog-modal-url");
    urlC.attr("src", "../window/GetImage.aspx");
    urlC.width(500);
    urlC.height(500);
}

function GetTemplate() {
    $("#dialog-modal").dialog({
        height: 450,
        width: 500,
        title: "网页模板",
        modal: true
    });
    var urlC = $("#dialog-modal-url");
    urlC.attr("src", "../window/GetTemplate.aspx?Control=txtTemplateFileName");
    urlC.width(460);
    urlC.height(410);
}

function GetTag(modelId) {
    $("#dialog-modal").dialog({
        height: 450,
        width: 500,
        title: "Tags选用",
        modal: true
    });
    var urlC = $("#dialog-modal-url");
    urlC.attr("src", "../window/GetTag.aspx?ModelId=" + modelId + "&Control=txtKey");
    urlC.width(460);
    urlC.height(410);
}

function CheckTitle() {
    $.ajax({
        type: "post",
        dataType: "JSON",
        url: "../DataHandler.ashx?Action=CheckTitle&Title=" + escape($("#txtContentTitle").val()) + "&ModelId=" + Request.QueryString("ModelId"),
        beforeSend: function() {

        },
        success: function(data) {
            alert(data.Msg);
        }
    });
}

function ToUnit(unit) {
    $get("txtUnit").value = unit;
    $get("txtUnit").focus();
    return false;
}